package com.flyaudio.xiaopengautopilot.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.flyaudio.xiaopengautopilot.R;
import com.flyaudio.xiaopengautopilot.presenter.IVehicleModule;

public class ResetDialog extends Dialog implements View.OnClickListener {

    private Context context;
    private int resLayout;

    private Button vehicle_reset_ok_bt, vehicle_reset_cancel_bt;

    public ResetDialog(Context context) {
        super(context);
    }

    public ResetDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public ResetDialog(Context context, int theme, int resLayout) {
        super(context, theme);
        this.context = context;
        this.resLayout = resLayout;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(resLayout);

        Window dialogWindow = getWindow();
        WindowManager manager = ((Activity) context).getWindowManager();
        WindowManager.LayoutParams params = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.TOP|Gravity.CENTER);

        initView();
    }

    private void initView() {
        vehicle_reset_ok_bt = (Button) findViewById(R.id.vehicle_reset_ok_bt);
        vehicle_reset_cancel_bt = (Button) findViewById(R.id.vehicle_reset_cancel_bt);

        vehicle_reset_ok_bt.setOnClickListener(this);
        vehicle_reset_cancel_bt.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.vehicle_reset_ok_bt:
                IVehicleModule.getInstance().resetKWhAvg();
                dismiss();
                break;
            case R.id.vehicle_reset_cancel_bt:
                dismiss();
                break;
        }
    }
}
